package com.sky.controller.user;

import com.sky.entity.Category;
import com.sky.result.Result;
import com.sky.service.impl.CategoryServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController("UserCategoryController")
@Slf4j
@Api(tags = "分类模块")
@RequestMapping("/user/category")
public class CategoryController {
    @Autowired
    private CategoryServiceImpl categoryService;
    @GetMapping("/list")
    @ApiOperation("根据类型查询分类")
    public Result getBytype(String type){
        List<Category> list = new ArrayList<>();
        if(type!=null)list = categoryService.getBytype(Integer.parseInt(type));
        else{
            list = categoryService.getBytype();
        }
        return Result.success(list);
    }

}
